package com.xmx.ndmalladmin.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.ApiOperation;
import com.xmx.ndmalladmin.entity.MenuEntity;
import com.xmx.ndmalladmin.service.MenuService;
import com.xmx.common.utils.PageUtils;
import com.xmx.common.utils.R;
import io.swagger.annotations.Api;


/**
 * 菜单管理
 *
 * @author fbb
 * @email boyinbing@126.com
 * @date 2021-08-11 01:54:37
 */
@Api(tags = "MenuController", description = "菜单管理服务")
@RestController
@RequestMapping("ndmalladmin/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;

    /**
     * 列表
     */
    @GetMapping("/list")
    //@RequiresPermissions("ndmalladmin:menu:list")
    @ApiOperation("获取所有菜单管理信息")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = menuService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{menuId}")
    //@RequiresPermissions("ndmalladmin:menu:info")
    @ApiOperation("获取指定id的菜单管理详情")
    public R info(@PathVariable("menuId") Long menuId){
		MenuEntity menu = menuService.getById(menuId);

        return R.ok().put("menu", menu);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation("添加菜单管理信息")
    //@RequiresPermissions("ndmalladmin:menu:save")
    public R save(@RequestBody MenuEntity menu){
		menuService.save(menu);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @ApiOperation("更新指定id菜单管理信息")
    //@RequiresPermissions("ndmalladmin:menu:update")
    public R update(@RequestBody MenuEntity menu){
		menuService.updateById(menu);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除指定id菜单管理信息")
    //@RequiresPermissions("ndmalladmin:menu:delete")
    public R delete(@RequestBody Long[] menuIds){
		menuService.removeByIds(Arrays.asList(menuIds));

        return R.ok();
    }

}
